package com.clz.test;

import com.clz.entity.Employee;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class T6 {
    public static void main(String[] args) {
        Employee e1=new Employee("武","田","男",19);
        Employee e2=new Employee("胡","桃","女",18);
        Employee e3=new Employee("顾","清寒","女",23);
        Employee e4=new Employee("胡","为","男",22);
        Employee e5=new Employee("季","莹莹","女",19);
        Employee e6=new Employee("武","田","女",18);
        List<Employee> list =new ArrayList<>();
        list.add(e1);
        list.add(e2);
        list.add(e3);
        list.add(e4);
        list.add(e5);
        list.add(e6);
        list.sort(new Comparator<Employee>() {
            @Override
            // 按照形式姓氏排序
            public int compare(Employee o1, Employee o2) {
                int surnameComparison = o1.getXing().compareTo(o2.getXing());
                if (surnameComparison != 0) {
                    return surnameComparison;
                }

                // 姓氏相同的情况下，按照名字的字典顺序排序
                int nameComparison = o1.getName().compareTo(o2.getName());
                if (nameComparison != 0) {
                    return nameComparison;
                }

                // 名字相同的情况下，女性优先
                if ("女".equals(o1.getSex()) && !"女".equals(o2.getSex())) {
                    return -1;
                } else if (!"女".equals(o1.getSex()) && "女".equals(o2.getSex())) {
                    return 1;
                }

                // 性别也相同的情况下，按照年龄升序排序
                return Integer.compare(o1.getAge(), o2.getAge());

            }
        });
        System.out.println(list);

    }
}
